# -*- coding: utf-8 -*-
from django.http import HttpResponse, HttpRequest
# from django.shortcuts import render
from appBook.models import mBook
from appBook.models import mComment
import sqlite3
import json
import logging
# from rest_framework import serializers
# from rest_framework.renderers import JSONRenderer
# from appBook.serializers import mBookSerializer
from rest_framework.views import APIView
from dss.Serializer import serializer

def response_as_json(data, foreign_penetrate=False):
	jsonString = serializer(data=data, output_type="json", foreign=foreign_penetrate)
	response = HttpResponse(
		# json.dumps(dataa, cls=MyEncoder),
		jsonString,
		content_type="application/json",
	)
	response["Access-Control-Allow-Origin"] = "*"
	return response

def json_response(data, code=200, foreign_penetrate=False, **kwargs):
	data = {
		"code": code,
		"msg": "成功",
		"data": data,
	}
	 return response_as_json(data, foreign_penetrate=foreign_penetrate)

def json_error(error_string="", code=500, **kwargs):
	data = {
		"code": code,
		"msg": error_string,
		"data": {}
	}
	data.update(kwargs)
	return response_as_json(data)

JsonResponse = json_response
JsonError = json_error

class ReturnJson(APIView):
	def get(self, request, *args, **kwargs):
		return JsonResponse("Hello world!!!!!!!!++++++中文测试")
